package com.ys.utils.yinsheng;

import com.alibaba.fastjson.JSONObject;
import com.ys.utils.yinsheng.yztdock.util.Result;
import com.ys.utils.yinsheng.yztdock.util.YztDockUtil;
import com.google.gson.JsonObject;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 银盛商户进件工具类
 */
public class MercUtil {

    private static final String success_code = "200";
    private static final String getYsToken = "getYsToken";
    private static final String uploadPicture = "uploadPicture";
    private static final String merchantRegistry = "merchant/registry";
    private static final String queryMerRegistry = "query/merchant/registry";
    private static final String channelReport = "channelReport";

    private static final String applyAccount = "applyAccount";
    private static final String verificationCode = "verificationCode";
    private static final String registerMobileBind = "registerMobileBind";
    private static final String getAccountInfo = "getAccountInfo";
    private static final String bindingBankCard = "bindingBankCard";
    private static final String confirmAndBindingCard = "confirmAndBindingCard";
    private static final String userBindingCardList = "userBindingCardList";
    private static final String unbindBankCard = "unbindBankCard";
    private static final String cardInformation = "cardInformation";
    private static final String walletBalance = "walletBalance";
    private static final String businessEnregister = "businessEnregister";
    private static final String searchDetailOfOrder = "trust-yspay/searchDetailOfOrder";
    private static final String transferPayRegister = "transferPayRegister";
    private static final String transferPayConfirm = "transferPayConfirm";
    private static final String refund = "trust-yspay/refund";
    private static final String refundSearch = "trust-yspay/refundSearch";


    /**
     *  获取token
     * @param appSecret 商户秘钥
     * @param userCode 商户用户号
     * @return token
     */
    public static Result<Map<String, String>> getYsToken(String appSecret, String userCode) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("userCode", userCode);
        String jsonStr = jsonObject.toString();
        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, getYsToken, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        String data = result.get("data");
        JSONObject jsonObject1 = JSONObject.parseObject(data);
        Map<String, String> map = new HashMap<>();
        map.put("token", jsonObject1.getString("token"));
        return Result.newSuccess(map);
    }

    /**
     * 上传图片
     * @param appSecret 商户秘钥
     * @param userCode 商户用户号
     * @param picType 图片类型 查看枚举
     * @param token getYsToken方法获取的token
     * @param file 上传图片文件
     * @return 图片id  picId
     */
    public static Result<Map<String, String>> uploadPicture(String appSecret, String userCode, String picType,
                                                     String token, File file) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("userCode", userCode);
        jsonObject.addProperty("picType", picType);
        jsonObject.addProperty("token", token);
        String jsonStr = jsonObject.toString();
        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, uploadPicture, file);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        String data = result.get("data");
        JSONObject jsonObject1 = JSONObject.parseObject(data);
        Map<String, String> map = new HashMap<>();
        map.put("picId", jsonObject1.getString("picId"));
        return Result.newSuccess(map);
    }

    /**
     * 商户进件
     * @param jsonObjectStr 进件对象
     * @return
     */
    public static Result<Map<String, String>> merchantRegistry(String jsonObjectStr) {
        Map<String, String> result = YztDockUtil.sendRequest(jsonObjectStr, merchantRegistry, null);
        //Map<String, String> result = new HashMap<>();
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess();
    }

    /**
     * 商户进件查询
     * @param appSecret 商户秘钥
     * @param userCode 商户用户号
     * @return
     */
    public static Result<Map<String, String>> queryMerRegistry(String appSecret, String userCode) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("userCode", userCode);
        String jsonStr = jsonObject.toString();
        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, queryMerRegistry, null);

        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        String data = result.get("data");
        JSONObject jsonObject1 = JSONObject.parseObject(data);
        Map<String, String> map = new HashMap<>();
        map.put("userCode", jsonObject1.getString("userCode"));
        map.put("state", jsonObject1.getString("state"));// 04-生效；03-待审核；09-审核失败
        map.put("ysUserCode", jsonObject1.getString("ysUserCode"));// 后续交易使用的商户号
        return Result.newSuccess(map);
    }

    /**
     * 商户报备
     * @param appSecret 商户秘钥
     * @param userCode 商户用户号
     * @return
     */
    public static Result<Map<String, String>> channelReport(String appSecret, String userCode) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        String jsonStr = jsonObject.toString();
        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, channelReport, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     *  个人开户申请
     * @param appSecret 商户秘钥
     * @param userCode 商户用户号
     * @param name 真实姓名
     * @param certifiNo 身份证号码
     * @return
     */
    public static Result<Map<String, String>> applyAccount(String appSecret, String userCode, String name, String certifiNo) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);

        jsonObject.addProperty("userType", "00"); // 用户类型 00-个人
        jsonObject.addProperty("accessTerminal", "01"); // 访问终端 00-PC,01-移动端
        jsonObject.addProperty("name", name); // 真实姓名
        jsonObject.addProperty("certifiType", "00"); // 证件类型 00-身份证 暂时只支持身份证
        jsonObject.addProperty("certifiNo", certifiNo); // 证件号码 暂时只支持身份证号码
        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, applyAccount, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     *  验证码 废弃
     * @param appSecret
     * @param userCode
     * @param mobile 注册手机号
     * @param funcode 验证类型 B1-手机号绑定、B2-修改注册手机号
     * @param flag 客户标识 A1-个户 A2-商户
     * @return
     */
    public static Result<Map<String, String>> verificationCode(String appSecret, String userCode, String mobile,
                                                               String funcode, String flag) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);

        jsonObject.addProperty("mobile", mobile); // 注册手机号
        jsonObject.addProperty("funcode", funcode); // 验证类型 B1-手机号绑定、B2-修改注册手机号
        jsonObject.addProperty("flag", flag); // 客户标识 A1-个户 A2-商户
        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, verificationCode, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     *  注册手机号绑定  废弃
     * @param appSecret
     * @param userCode
     * @param mobile 手机号
     * @param verificationCode 验证码
     * @param flag 客户标识 A1-个户 A2-商户
     * @return
     */
    public static Result<Map<String, String>> registerMobileBind(String appSecret, String userCode, String mobile,
                                                               String verificationCode, String flag) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);

        jsonObject.addProperty("mobile", mobile); // 注册手机号
        jsonObject.addProperty("verificationCode", verificationCode); // 验证码
        jsonObject.addProperty("flag", flag); // 客户标识 A1-个户   A2-商户
        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, registerMobileBind, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 用户信息查询
     * @param appSecret
     * @param userCode
     * @return
     */
    public static Result<Map<String, String>> getAccountInfo(String appSecret, String userCode) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, getAccountInfo, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 银行卡绑定申请
     * @param appSecret
     * @param userCode
     * @param bankAccountNo 银行卡号
     * @param mobile 银行预留手机号
     * @return
     */
    public static Result<Map<String, String>> bindingBankCard(String appSecret, String userCode, String bankAccountNo, String mobile) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("bankAccountNo", bankAccountNo); // 银行卡号
        jsonObject.addProperty("mobile", mobile); // 银行预留手机号

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, bindingBankCard, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 银行卡绑定确认
     * @param appSecret
     * @param userCode
     * @param sn 签约登记流水号 银行卡绑定申请接口返回
     * @param smsCode 短信验证码
     * @return cardToken 解绑卡时使用
     */
    public static Result<Map<String, String>> confirmAndBindingCard(String appSecret, String userCode, String sn, String smsCode) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("sn", sn); // 签约登记流水号 银行卡绑定申请接口返回
        jsonObject.addProperty("smsCode", smsCode); // 短信验证码

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, confirmAndBindingCard, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 绑定银行卡查询
     * @param appSecret
     * @param userCode
     * @return
     */
    public static Result<Map<String, String>> userBindingCardList(String appSecret, String userCode) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, userBindingCardList, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 解绑银行卡
     * @param appSecret
     * @param userCode
     * @param cardToken 绑定银行卡片编号
     * @return
     */
    public static Result<Map<String, String>> unbindBankCard(String appSecret, String userCode, String cardToken) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("cardToken", cardToken); // 绑定银行卡片编号

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, unbindBankCard, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     *  卡bin查询 只能查询已绑定的银行卡
     * @param appSecret
     * @param userCode
     * @param bankAccountNo 银行卡号
     * @return
     */
    public static Result<Map<String, String>> cardInformation(String appSecret, String userCode, String bankAccountNo) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("bankAccountNo", bankAccountNo);

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, cardInformation, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     *  钱包余额查询
     * @param appSecret
     * @param userCode
     * @return balance 单位 元
     */
    public static Result<Map<String, String>> walletBalance(String appSecret, String userCode) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, walletBalance, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 充值申请
     * @param appSecret
     * @param userCode
     * @param amount 金额[0.01-999999999.99]
     * @param orderId 商户订单号(32位)
     * @param cardToken 绑定银行接口获取的卡片编号
     * @return
     */
    public static Result<Map<String, String>> rechargeApply(String appSecret, String userCode,
                                                                 String amount, String orderId, String cardToken) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("amount", amount); // 金额[0.01-999999999.99]
        jsonObject.addProperty("orderId", orderId); // 商户订单号(32位)
        jsonObject.addProperty("cardToken", cardToken); // 绑定银行接口获取的卡片编号
        jsonObject.addProperty("businesType", "01"); // 业务类型 01

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, businessEnregister, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 提现
     * @param appSecret
     * @param userCode
     * @param amount 金额[0.01-999999999.99]
     * @param orderId 商户订单号(32位)
     * @param cardToken 绑定银行接口获取的卡片编号
     * @return
     */
    public static Result<Map<String, String>> withdraw(String appSecret, String userCode,
                                                            String amount, String orderId, String cardToken) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("amount", amount); // 金额[0.01-999999999.99]
        jsonObject.addProperty("orderId", orderId); // 商户订单号(32位)
        jsonObject.addProperty("cardToken", cardToken); // 绑定银行接口获取的卡片编号
        jsonObject.addProperty("businesType", "02"); // 业务类型 02

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, businessEnregister, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if ("200".equals(code) || "325".equals(code)) {
            return Result.newSuccess(result);
        }
        return Result.newFailure(-1, msg);
    }

    /**
     * 内部转账
     * @param appSecret
     * @param businesType 交易类型 （00-用户转用户、01-商户转商户、02-商户转用户、03-商户转平台、04-平台转商户、05-平台转用户）
     * @param amount 金额[0.01-999999999.99]
     * @param orderId 商户订单号(32位)
     * @param payerUserCode 付款方用户号
     * @param payerName 付款方用户名
     * @param payeeUserCode 收款方用户号
     * @param payeeName 收款方用户名
     * @return sn 申请流水号 确认转账时使用
     */
    public static Result<Map<String, String>> transferPayRegister(String appSecret, String businesType,
                                                       String amount, String orderId, String payerUserCode,
                                                                  String payerName, String payeeUserCode, String payeeName) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("payerUserCode", payerUserCode); // 付款方用户号
        jsonObject.addProperty("payerName", payerName); // 付款方用户名
        jsonObject.addProperty("payeeUserCode", payeeUserCode); // 收款方用户号
        jsonObject.addProperty("payeeName", payeeName); // 收款方用户名
        jsonObject.addProperty("businesType", businesType); // 交易类型 （00-用户转用户、01-商户转商户、02-商户转用户、03-商户转平台、04-平台转商户、05-平台转用户）
        jsonObject.addProperty("amount", amount); // 金额[0.01-999999999.99]
        jsonObject.addProperty("orderId", orderId); // 商户订单号(32位)
        jsonObject.addProperty("note", "转账"); // 商户订单号(32位)

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, transferPayRegister, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 内部转账确认  废弃
     * @param appSecret
     * @param businesType 交易类型 （00-用户转用户、01-商户转商户、02-商户转用户、03-商户转平台、04-平台转商户、05-平台转用户）
     * @param payerUserCode 付款方用户号
     * @param sn 申请流水号
     * @return
     */
    public static Result<Map<String, String>> transferPayConfirm(String appSecret, String businesType,
                                                                  String payerUserCode, String sn) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("payerUserCode", payerUserCode); // 付款方用户号
        jsonObject.addProperty("businesType", businesType); // 交易类型 （00-用户转用户、01-商户转商户、02-商户转用户、03-商户转平台、04-平台转商户、05-平台转用户）
        jsonObject.addProperty("sn", sn); // 申请流水号


        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, transferPayConfirm, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 钱包消费申请 废弃
     * @param appSecret
     * @param userCode
     * @param amount 金额[0.01-999999999.99]
     * @param orderId 商户订单号(32位)
     * @param merchantId 商户的商户号usercode
     * @param merchantName 商户名称
     * @return
     */
    public static Result<Map<String, String>> walletPayApply(String appSecret, String userCode,
                                                            String amount, String orderId,
                                                            String merchantId, String merchantName) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("amount", amount); // 金额[0.01-999999999.99]
        jsonObject.addProperty("orderId", orderId); // 商户订单号(32位)
        jsonObject.addProperty("merchantId", merchantId); // 商户的商户号usercode
        jsonObject.addProperty("merchantName", merchantName); // 商户名称
        jsonObject.addProperty("tranBissType", "1"); // 交易类型:1及时到账；2担保交易
        jsonObject.addProperty("businesType", "03"); // 业务类型 03

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, businessEnregister, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 快捷消费申请 废弃
     * @param appSecret
     * @param userCode
     * @param amount 金额[0.01-999999999.99]
     * @param orderId 商户订单号(32位)
     * @param cardToken 绑定银行接口获取的卡片编号
     * @param merchantId 商户的商户号usercode
     * @param merchantName 商户名称
     * @return
     */
    public static Result<Map<String, String>> quickPayApply(String appSecret, String userCode,
                                                            String amount, String orderId, String cardToken,
                                                            String merchantId, String merchantName) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("amount", amount); // 金额[0.01-999999999.99]
        jsonObject.addProperty("orderId", orderId); // 商户订单号(32位)
        jsonObject.addProperty("cardToken", cardToken); // 绑定银行接口获取的卡片编号
        jsonObject.addProperty("merchantId", merchantId); // 商户的商户号usercode
        jsonObject.addProperty("merchantName", merchantName); // 商户名称
        jsonObject.addProperty("tranBissType", "1"); // 交易类型:1及时到账；2担保交易
        jsonObject.addProperty("businesType", "04"); // 业务类型 04

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, businessEnregister, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     * 订单状态查询
     * @param appSecret
     * @param userCode
     * @param orderId 订单id
     * @return
     */
    public static Result<Map<String, String>> searchDetailOfOrder(String appSecret, String userCode,
                                                                  String orderId) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("appUserCode", userCode);
        jsonObject.addProperty("orderId", orderId);

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, searchDetailOfOrder, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (success_code.equals(code) || "461".equals(code)) {
            return Result.newSuccess(result);
        }
        return Result.newFailure(-1, msg);
    }

    /**
     *
     * @param appSecret
     * @param refundOrderId 退款订单号
     * @param refundAmount 退款金额
     * @param orderId 原订单编号
     * @return
     */
    public static Result<Map<String, String>> refund(String appSecret, String refundOrderId, String refundAmount,
                                                                  String orderId) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("refundOrderId", refundOrderId);
        jsonObject.addProperty("refundAmount", refundAmount);
        jsonObject.addProperty("orderId", orderId);

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, refund, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     *
     * @param appSecret
     * @param refundOrderId 退款订单号
     * @param orderId 原订单编号
     * @return
     */
    public static Result<Map<String, String>> refundSearch(String appSecret, String refundOrderId,
                                                     String orderId) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("appSecret", appSecret);
        jsonObject.addProperty("refundOrderId", refundOrderId);
        jsonObject.addProperty("orderId", orderId);

        String jsonStr = jsonObject.toString();

        Map<String, String> result = YztDockUtil.sendRequest(jsonStr, refundSearch, null);
        String code = result.get("code");
        String msg = result.get("msg");
        if (!success_code.equals(code)) {
            return Result.newFailure(-1, msg);
        }
        return Result.newSuccess(result);
    }

    /**
     *
     * @param jsonObject
     * @return
     */
    public static Result<Map<String, String>> registerNotify(JsonObject jsonObject){


        return null;
    }


}
